package com.siyuanren.gcocp.service.impl;

import com.siyuanren.gcocp.entity.WxCourseStatistics;
import com.siyuanren.gcocp.entity.WxCourseStatisticsExample;
import com.siyuanren.gcocp.enumm.StatisticTypeEnum;
import com.siyuanren.gcocp.mapper.base.WxCourseStatisticsMapper;
import com.siyuanren.gcocp.service.CourseStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.service.impl
 * Date         2018/6/25
 * Time         15:12
 * Description
 */
@Service
@Slf4j
public class CourseStatisticsImpl implements CourseStatisticsService {
    @Autowired
    private WxCourseStatisticsMapper courseStatisticsMapper;

    @Override
    public WxCourseStatistics getCourseOrderCount(Integer courseId) {
        WxCourseStatisticsExample example = new WxCourseStatisticsExample();
        example.or().andTypeEqualTo(StatisticTypeEnum.CourseStati.ordinal())
                .andGoalIdEqualTo(courseId);
        List<WxCourseStatistics> list = courseStatisticsMapper.selectByExample(example);
        if (list.isEmpty()) {
            return null;
        } else {
            return list.get(0);
        }
    }

    @Override
    public WxCourseStatistics getChapterPlayCount(Integer chapterId) {
        WxCourseStatisticsExample example = new WxCourseStatisticsExample();
        example.or().andTypeEqualTo(StatisticTypeEnum.ChapterStati.ordinal())
                .andGoalIdEqualTo(chapterId);
        List<WxCourseStatistics> list = courseStatisticsMapper.selectByExample(example);
        if (list.isEmpty()) {
            return null;
        } else {
            return list.get(0);
        }
    }
}
